/*
 * tcpipsim.h
 *
 *  Created on: 2009-3-31
 *      Author: tian
 */

#ifndef TCPIPSIM_H_
#define TCPIPSIM_H_

#include"myip.h"
#include"mytcp.h"
#include"msgtype.h"
#include<pthread.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>

extern pthread_mutex_t mutex;

/* this function initialize our tcp/ip stack
 * at least it should include:
 * 1.set its ip address and get a message queue
 * 2.set another tcp/ip stack ip-message_queue pair(ip route)
 * Return Values:
 * it returns -1 for some error,and 0 is returned if succeed
 */
int init();

/* this function handle tcp timer.it calls tcp_timer() to
 * achieve its goals
 */
void timer_thread_handler();

/* this function handle network stuff.
 * All network activities, such as sending/recieving package,
 * changing tcp state and interactive works with users,should
 * be under its control.
 */
int network_thread_handler(int msgqid);

void handle_socket(msg *);
void handle_read(msg *);
void handle_write(msg *);
void handle_close(msg *);
void handle_listen(msg *);
void handle_accept(msg *);
void handle_bind(msg *);
void handle_connect(msg *);
//void handle_timeout();

#endif /* TCPIPSIM_H_ */
